/***************************************************************************\
 * The Mattise Kernel														*
 * Copyright 2007 Matthew Iselin											*
 * THIS FILE is Public Domain												*
 *																			*
 * filesys.h																*
 *																			*
 * Handles all filesystem installations and controls any reads/writes		*
 *																			*
\***************************************************************************/

// Pragmas
#pragma once

// Includes
#include <system.h>
#include <io.h>

// Constants
#define INVALID_FILE		-1
#define NOBYTESREAD			-1
#define NOBYTESWRITTEN		-1
#define NOSEEK				-1

// Types

// a block of functions
struct FuncBlock {
	int (*open)(int,const char*,const char*,void*);	// first argument is the device, not a descriptor id
	int (*read)(int,char*,int,int,void*);			// first is a descriptor id
	int (*write)(int,char*,int,int,void*);			// <see above>
	int (*getc)(int,void*);							// <see above>
	int (*putc)(int,int,void*);						// <see above>
//	int (*seek)(int,int,int,void*);					// <see above>
	int (*close)(int,void*);						// first argument is a device (all this function has to do is close
													//								any devices it opens)
	int (*iseof)(int,void*);						// allows us to find out where exactly the end of the file is
	int (*filesize)(int,void*);						// allows us to find out how big the file is
};

// Prototypes

// gets a descriptor's current offset
int GetDescriptorOffset( int desc );

// filesys_open: opens a file (if the device is null and the path is dev, then it'll call open for you)
// returns a descriptor for the file
int filesys_open( const char* file, const char* mode );

// filesys_read: reads bytes from a file
int filesys_read( int desc, char* buff, int buffsz, int cnt );

// filesys_write: writes bytes to a file
int filesys_write( int desc, char* buff, int buffsz, int cnt );

// filesys_seek: seeks to a new location within the file
int filesys_seek( int desc, int newloc, int whence );

// filesys_getc: gets a character from the file
int filesys_getc( int desc );

// filesys_putc: puts a character into the file
int filesys_putc( int desc, int c );

// filesys_close: closes the file
int filesys_close( int desc );

// filesys_eof: are we at EOF?
int filesys_eof( int desc );

// filesys_filesize: gets the size of a file
int filesys_filesize( int desc );

// RegisterFileSystem: registers a filesystem for a device
int RegisterFileSystem( const char* nm, int usrdata_size, int device, struct FuncBlock* myFunctions );
